﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Drawing;

public partial class ContactData : System.Web.UI.UserControl
{

    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Expires = -1;

        if (!IsPostBack)
        {
            LoadCustData();
        }
    }

    protected void btnSubmit_Click(object sender, System.EventArgs e)
    {

        if (IsTelephone(tbPriPhone.Text))
        {
            ((DataAccess)Session["App"]).PutCallData("firstname", tbFirstName.Text);
            ((DataAccess)Session["App"]).PutCallData("lastname", tbLastName.Text);
            ((DataAccess)Session["App"]).PutCallData("primaryphone", tbPriPhone.Text);
            ((DataAccess)Session["App"]).PutCallData("alternatephone", tbSecPhone.Text);
            ((DataAccess)Session["App"]).PutCallData("email", tbEmail.Text);

            lblError.ForeColor = Color.Blue;
            lblError.Text = "Contact Info submitted successfully";
        }
        else
        {
            lblError.ForeColor = Color.Red;
            lblError.Text = "Invalid Phone";
        }

    }

    private bool IsTelephone(string strTel)
    {
        if (strTel.Trim().Length == 10)
        {
            long result;

            return Int64.TryParse(strTel, out result);
        }
        else
        {
            return false;
        }
    }

    public void LoadCustData()
    {
        tbListid.Text = ((DataAccess)Session["App"]).GetCallData("enterpriselistid");
        tbFirstName.Text = ((DataAccess)Session["App"]).GetCallData("firstname");
        tbLastName.Text = ((DataAccess)Session["App"]).GetCallData("lastname");
        tbPriPhone.Text = ((DataAccess)Session["App"]).GetCallData("primaryphone");
        tbSecPhone.Text = ((DataAccess)Session["App"]).GetCallData("alternatephone");
        tbEmail.Text = ((DataAccess)Session["App"]).GetCallData("email");
    }

}
